define([
    "UtilDir/util",
    "UtilDir/tool",
    "UtilDir/org/selectOrg",
    "UtilDir/searchBlock",
    "static/app/hddc/hddccjcommon/hddccjCommon",
    "UtilDir/dialog",
    "Echarts", "Date", "DateCN", "css!DateCss",
    "EasyUI", "EasyUI-lang"
], function (Util, Tool, SelectOrg, SearchBlock, HddccjCommon, Dialog, Echarts) {
    /**
     * 页面初始化
     */
    var init = function () {
        queryBtnBind();
        downloadDialog();
        uploadDialog();
        HddccjCommon.initProjectSelect("projectName");
        HddccjCommon.initTaskSelect("projectName", "taskName");
        initDatetimePicker();
        createDZDCBarChart();
    };

    // 几个表的数组
    var datas = ['aabb', 'bbb'];

    var createDZDCBarChart = function () {
        var myChart = Echarts.init(document.getElementById('barChart'));
        var option = {
            title: {
                text: '地质调查工作量数据',
                left: '30%'
            },
            tooltip: {},
            xAxis: {
                name:'外业采集量',
                data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
            },
            grid: {
                left: '20%',
                right: '20%',
                top: '20%',
                bottom: '10%'
            },
            yAxis: {name:'工作量'},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20],
                barWidth: 30,
                itemStyle: {
                    normal: {
                        //每个柱子的颜色即为colors数组里的每一项，如果柱子数目多于colors的长度，则柱子颜色循环使用该数组
                        color: function (params) {
                            var colors = ['#00CCCC', '#CCCC00', '#FF9900', '#66CC66', '#0099FF', '#CC9999'];
                            return colors[params.dataIndex];
                        }
                    },
                },
            }]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);

        // $.ajax({
        //     url: getHddcWyFaultsvypointController() + "/"+id,
        //     type: "get",
        //     data:{
        //
        //     },
        //     success: function (data) {
        //     }
        // });
    }
    var initDatetimePicker = function () {
        $("#date1").datetimepicker({
            //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
            language: "cn",
            //输出格式化
            format: 'yyyy-mm-dd',
            //直接选择‘今天’
            todayBtn: true,
            //设置最精确的时间选择视图
            minView: 'month',
            //高亮当天日期
            todayHighlight: true,
            //选择完毕后自动关闭
            autoclose: true
        });

        $("#date2").datetimepicker({
            //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
            language: "cn",
            //输出格式化
            format: 'yyyy-mm-dd',
            //直接选择‘今天’
            todayBtn: true,
            //设置最精确的时间选择视图
            minView: 'month',
            //高亮当天日期
            todayHighlight: true,
            //选择完毕后自动关闭
            autoclose: true
        });
    }
    var queryBtnBind = function () {
        $("#btnSearch").click(function () {
            createDZDCBarChart();
        });
        $("#btnReset").click(function () {
            $("#date1").val("");
            $("#date2").val("");
            $("#projectName").val("");
            $("#taskName").val("");
        });
    };
    var downloadDialog = function () {
        $("#downLoad").click(function () {
            debugger
            //为弹出框增加操作按钮
            var buttons = [];
            buttons.push({
                name: "下载",
                callback: function () {
                    //此处写扩展代码
                    alert(111);
                    dialog.hide();
                }
            });
            var dialog = Dialog({
                id: "BaseDialog",
                title: "下载外业数据",
                width: "500px",
                height: "70px",
                dialogSize: "",               //modal-lg或modal-sm
                body: '<div class="form-group">\n' +
                    '                        <label for="taskName" class="col-md-4 control-label"></span>请选择:</label>\n' +
                    '                        <div class="col-md-8">\n' +
                    '                            <select class="form-control" id="downloadTable">\n' +
                    '                            </select>\n' +
                    '                        </div>\n' +
                    '                    </div>',
                buttons: buttons
            });
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $.each(datas, function (idx, item) {
                html += "<option value=" + item + ">" + item + "</option>";
            });
            $("#downloadTable").append(html);
            //可以通过返回的dialog对象调用相关方法
            //dialog.setBody("修改内容");
            //dialog.show();
        });
    }


    //导出（上传）
    var uploadDialog = function () {
        $("#upLoad").on("click", function () {
            $("#uploadModal").modal();
            $("#uploadModal").on("shown.bs.modal", function () {
                var url = getServer() + "/excel/重要地名地物-点.xls";
                $("#downloadZwExcelTemplate").attr("href", url);
            });
            //初始化下拉select
            var html = '';
            $.each(datas, function (idx, item) {
                html += "<option value=" + item + ">" + item + "</option>";
            });
            $("#uploadSelect").append(html);

            $('#uploadButton').off("click");
            $("#uploadButton").on("click", function () {
                var uploadinput = document.getElementById("uploadFile");
                if (uploadinput.value == "") {
                    Util.alert("上传前请先选择文件!");
                    return;
                }
                var formData = new FormData();
                formData.append("file", uploadinput.files[0]);
                $.ajax({
                    url: getHddcImportantsurfacefeatureController() + "/importDisaster",
                    data: formData,
                    processData: false, //因为data值是FormData对象，不需要对数据做处理。
                    contentType: false,
                    type: "POST",
                    success: function (data) {
                        $('#uploadModal').modal('hide');
                        uploadinput.value = null;
                        Util.alert(data);
                        createHddcImportantsurfacefeatureGrid();
                    }
                });
            });

        })
    };

    return {
        init: init
    };
});
